﻿using System.Web.Mvc;
using DevExpress.Web.Mvc;

namespace DevExpress.Web.Demos {
    public partial class RowsController: DemoController {
        public override string Name { get { return "Rows"; } }

        public ActionResult Index() {
            return RedirectToAction("FocusedRow");
        }
        public ActionResult EmployeeImage() {
            if(Request.QueryString[GridViewRowsDemosHelper.ImageQueryKey] != null) {
                int employeeId = int.Parse(Request.QueryString[GridViewRowsDemosHelper.ImageQueryKey]);
                Response.ContentType = "image";
                var photo = NorthwindDataProvider.GetEmployeePhoto(employeeId);
                if(photo != null)
                    Response.BinaryWrite(photo.ToArray());
                Response.End();
            }
            return null;
        }
    }

    public class GridViewRowsDemosHelper {
        public const string ImageQueryKey = "DXImage";
        public static string GetEmployeeImageRouteUrl() {
            return DevExpressHelper.GetUrl(new { Controller = "Rows", Action = "EmployeeImage" });
        }
    }
}
